package models

import (
	"first-gin/db"
)

type User struct {
	Id   int
	Name string
}

func (User) TableName() string {
	return "user"
}

func GetUserTest(id int) (User, error) {
	var user User
	err := db.Db.Where("id = ?", id).First(&user).Error
	return user, err
}

func AddUser(userName string) (int, error) {
	user := User{Name: userName}
	err := db.Db.Create(&user).Error
	return user.Id, err
}

func UpdateUser(user User) error {
	return db.Db.Model(&user).Where("id = ?", user.Id).Update("name", user.Name).Error
}

func DeletedById(id int) error {
	return db.Db.Where("id = ?", id).Delete(&User{}).Error
}
